/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.own.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.own.entity.OwnCompanyBasicInformation;
import com.jeesite.modules.own.service.OwnCompanyBasicInformationService;

/**
 * 企业基本信息Controller
 * @author F
 * @version 2019-09-29
 */
@Controller
@RequestMapping(value = "${adminPath}/own/ownCompanyBasicInformation")
public class OwnCompanyBasicInformationController extends BaseController {

	@Autowired
	private OwnCompanyBasicInformationService ownCompanyBasicInformationService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public OwnCompanyBasicInformation get(String id, boolean isNewRecord) {
		return ownCompanyBasicInformationService.getCompanyBasicInformation();
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("own:ownCompanyBasicInformation:view")
	@RequestMapping(value = {"from"})
	public String list(OwnCompanyBasicInformation ownCompanyBasicInformation, Model model) {
		model.addAttribute("ownCompanyBasicInformation", ownCompanyBasicInformation);
		return "modules/own/ownCompanyBasicInformationList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("own:ownCompanyBasicInformation:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<OwnCompanyBasicInformation> listData(OwnCompanyBasicInformation ownCompanyBasicInformation, HttpServletRequest request, HttpServletResponse response) {
		ownCompanyBasicInformation.setPage(new Page<>(request, response));
		Page<OwnCompanyBasicInformation> page = ownCompanyBasicInformationService.findPage(ownCompanyBasicInformation);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("own:ownCompanyBasicInformation:view")
	@RequestMapping(value = {"list",""})
	public String form(OwnCompanyBasicInformation ownCompanyBasicInformation, Model model) {
		//System.out.println(ownCompanyBasicInformation);
		//OwnCompanyBasicInformation ownCompanyBasicInformation1 = ownCompanyBasicInformationService.get(ownCompanyBasicInformation);
		model.addAttribute("ownCompanyBasicInformation", ownCompanyBasicInformation);
		return "modules/own/ownCompanyBasicInformationForm";
	}

	/**
	 * 保存企业基本信息
	 */
	@RequiresPermissions("own:ownCompanyBasicInformation:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated OwnCompanyBasicInformation ownCompanyBasicInformation) {
		ownCompanyBasicInformationService.save(ownCompanyBasicInformation);
		return renderResult(Global.TRUE, text("保存企业基本信息成功！"));
	}
	
	/**
	 * 删除企业基本信息
	 */
	@RequiresPermissions("own:ownCompanyBasicInformation:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(OwnCompanyBasicInformation ownCompanyBasicInformation) {
		ownCompanyBasicInformationService.delete(ownCompanyBasicInformation);
		return renderResult(Global.TRUE, text("删除企业基本信息成功！"));
	}
	
}